package eventplanner.rest.exceptionmappers;

import eventplanner.ejb.exceptions.UnauthorizedException;

import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.ext.ExceptionMapper;
import javax.ws.rs.ext.Provider;

@Provider
public class RestUnauthorizedExceptionHandler implements ExceptionMapper<UnauthorizedException> {

	private static final String ERROR_MESSAGE = "You don't have access to this resource. Please login first.";

	@Override
	public Response toResponse(UnauthorizedException e) {
		return Response.status(Response.Status.UNAUTHORIZED).entity(ERROR_MESSAGE).type(MediaType.TEXT_PLAIN_TYPE).build();
	}
}
